<!DOCTYPE html>
<html>
    
    <head>
        <meta charset="utf-8">
        <title>
            X-admin v1.0
        </title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="format-detection" content="telephone=no">
        <link rel="stylesheet" href="__PUBLIC__/admin/css/x-admin.css" media="all">
    </head>
    
    <body>
        <div class="x-body">
            <form action="" method="post" class="layui-form layui-form-pane">
                <div class="layui-form-item">
                    <label for="name" class="layui-form-label">
                        <span class="x-red">*</span>所在区域
                    </label>
                    <div class="layui-input-inline">
                        <select name="sk_city" id="" required lay-verify="required">
                                <option value="{$showke_info.sk_city}">{$showke_info.sk_city}</option>
                            <?php foreach ($city_quyu as $c) { ?>
                                <option value="{$c.city_name}">{$c.city_name}</option>
                            <?php } ?>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_username" class="layui-form-label">
                        <span class="x-red">*</span>授课范围
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" name="address" required lay-verify="required" placeholder="输入详细地址" autocomplete="off" class="layui-input" value="{$showke_info.address}">
                    </div>
                    <div class="layui-form-mid layui-word-aux">
                        <span class="x-red">*</span>格式：地铁三号线附近
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_username" class="layui-form-label">
                        <span class="x-red">*</span>授课时费
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" name="price" required lay-verify="required" placeholder="输入价格" autocomplete="off" class="layui-input" value="{$showke_info.price}">
                    </div>
                    <div class="layui-form-mid layui-word-aux">
                        <span class="x-red">*</span>单位 (元)
                    </div>
                </div>
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">
                        授课年级
                    </label>
                    <table  class="layui-table layui-input-block">
                        <tbody>
                            <tr>
                                <td>授课年级</td>
                                <td>
                            <div class="layui-input-block">
                                <p>选择大类：</p>
                                <div style="position: relative;left: 80px;top:-20px;">
                                    <p>
                                    <?php foreach ($whs as $g) { ?>
                                    <?php if ($wh == $g['grade_name']) { ?>
                                        <a href="{:U('admin/laoshi/showke_info',array('id'=>$id,'wh'=>$g['grade_name'],'newcity'=>$city))}" style="background-color: #30C76C;color: #fff !important;padding: 2px 5px;border-radius: 5px;margin-right: 10px;">{$g['grade_name']}</a>
                                    <?php }else { ?>
                                        <a href="{:U('admin/laoshi/showke_info',array('id'=>$id,'wh'=>$g['grade_name'],'newcity'=>$city))}" style="background-color: #F0F0F0;padding: 2px 5px;border-radius: 5px;margin-right: 10px;">{$g['grade_name']}</a>
                                    <?php } ?>
                                    <?php } ?>
                                    </p>
                                </div>
                                <p></p>
                            </div>
                            <div>
                                <p>选择年级：</p>
                                <div style="position: relative;left: 80px;top:-20px;">
                                <p>
                                <?php foreach ($grades as $g) { ?>
                                <?php if ($grade_name == $g['grade_name']) { ?>
                                    <a href="{:U('admin/laoshi/showke_info',array('id'=>$id,'wh'=>$wh,'grade'=>$g['grade_name'],'newcity'=>$city))}" style="background-color: #30C76C;color: #fff !important;padding: 2px 5px;border-radius: 5px;margin-right: 10px;">{$g['grade_name']}</a>
                                <?php }else { ?>
                                    <a href="{:U('admin/laoshi/showke_info',array('id'=>$id,'wh'=>$wh,'grade'=>$g['grade_name'],'newcity'=>$city))}" style="background-color: #F0F0F0;padding: 2px 5px;border-radius: 5px;margin-right: 10px;">{$g['grade_name']}</a>
                                <?php } ?>
                                <?php } ?>
                                </p>
                                </div>
                                <p></p>
                            </div>
                            <div style="height: 50px;">
                                <p>选择科目：</p>
                                <div style="position: relative;left: 80px;top:-20px;">       
                                <p>
                                <?php foreach ($kecheng as $k) { ?>
                                <?php if ($subject_name == $k['grade_name']) { ?>
                                    <a href="{:U('admin/laoshi/showke_info',array('id'=>$id,'wh'=>$wh,'grade'=>$grade_name,'subject'=>$k['grade_name'],'newcity'=>$city))}" style="background-color: #30C76C;color: #fff !important;padding: 2px 5px;border-radius: 5px;margin-right: 10px;">{$k['grade_name']}</a>
                                <?php }else { ?>
                                    <a href="{:U('admin/laoshi/showke_info',array('id'=>$id,'wh'=>$wh,'grade'=>$grade_name,'subject'=>$k['grade_name'],'newcity'=>$city))}" style="background-color: #F0F0F0;padding: 2px 5px;border-radius: 5px;margin-right: 10px;">{$k['grade_name']}</a>
                                <?php } ?>  
                                <?php } ?>
                                </p>
                                </div>
                                <span style="color: red;">已选中：{$wh} / {$grade_name} / {$subject_name}</span>
                                <span style="color: #222;font-weight: bold;border: 1px solid;"> 上次选中：{$showke_info.class} / {$showke_info.grades} / {$showke_info.subject}</span>
                            </div>
                                </td>
                            </tr>
                            <tr>
                                <td>授课方式</td>
                                <td>
                                    <div class="layui-input-block">
                                        <?php foreach ($methods as $m) { ?>
                                            <input class="methods" name="methods" required lay-verify="required" type="checkbox" value="{$m['id']}"<?php if (in_array($m['id'], $showke_methods)) { ?>
                                          checked <?php } ?>>{$m.method_name}
                                        <?php } ?> 
                                    </div>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
                <div class="layui-form-item layui-form-text">
                    <label for="desc" class="layui-form-label">
                        授课时间
                    </label>
                            <table style="clear:both; width:100%;" class="tbhju">
                                <colgroup>
                                    <col width="16%">
                                    <col width="12%">
                                    <col width="12%">
                                    <col width="12%">
                                    <col width="12%">
                                    <col width="12%">
                                    <col width="12%">
                                    <col width="12%">
                                </colgroup>
                                <thead>
                                    <tr id="uinp">
                                        <th>&nbsp;</th>
                                        <th>星期一</th>
                                        <th>星期二</th>
                                        <th>星期三</th>
                                        <th>星期四</th>
                                        <th>星期五</th>
                                        <th>星期六</th>
                                        <th>星期日</th>
                                    </tr>
                                </thead>
                                <tbody id="uMw">
                                    <tr>
                                        <td class="timE">上午</td>
                                        <?php  foreach ($showke_time_sw as $t) { ?>
                                        <td class="sL"><input class="showke_time" type="checkbox" name="sm_shijian" value="{$t.id}"<?php if (in_array($t['id'], $shouke_times)) { ?>
                                          checked
                                        <?php } ?> /></td>
                                        <?php } ?>
                                    </tr>
                                    <tr>
                                        <td class="timE">下午</td>
                                        <?php  foreach ($showke_time_xw as $t) { ?>
                                        <td class="sL"><input class="showke_time" type="checkbox" name="sm_shijian" value="{$t.id}"<?php if (in_array($t['id'], $shouke_times)) { ?>
                                          checked
                                        <?php } ?> /></td>
                                        <?php } ?>
                                    </tr>
                                    <tr>
                                        <td class="timE">晚上</td>
                                        <?php  foreach ($showke_time_ws as $t) { ?>
                                        <td class="sL"><input class="showke_time" type="checkbox" name="sm_shijian" value="{$t.id}"<?php if (in_array($t['id'], $shouke_times)) { ?>
                                          checked
                                        <?php } ?> /></td>
                                        <?php } ?>
                                    </tr>
                                </tbody>
                            </table>
                </div>
                <div class="layui-form-item">
                <input type="hidden" name="uid" value="{$id}">

                <input type="hidden" name="wh" value="{$wh}">
                <input type="hidden" name="grades" value="{$grade_name}">
                <input type="hidden" name="subject" value="{$subject_name}">
                <button class="layui-btn" lay-submit="" lay-filter="add">增加</button>
              </div>
            </form>
        </div>
        <script src="__PUBLIC__/admin/lib/layui/layui.js" charset="utf-8">
        </script>
        <script src="__PUBLIC__/admin/js/x-layui.js" charset="utf-8">
        </script>
        <script>
            layui.use(['form','layer','layedit' ,'laypage', 'element','upload'], function(){
                $ = layui.jquery;
              var form = layui.form()
              ,laypage = layui.laypage
              ,layedit = layui.layedit
              ,element = layui.element()
              ,upload = layui.upload
              ,layer = layui.layer;

              //创建一个编辑器
              // var editIndex = layedit.build('L_content', {height: 132,
              //               tool: ['strong','italic','underline','del','left', 'center', 'right', '|', 'face','link']
              //               });

              //监听提交
              form.on('submit(add)', function(data){
                //授课年级
                var grade = new Array();
                var chenked=$(".grade:checked").each(function(){
                   grade.push($(this).val()); 
                })
                data.field.grade = grade;
                //上门方式
                var methods = new Array();
                var chenked=$(".methods:checked").each(function(){
                   methods.push($(this).val()); 
                })
                data.field.methods = methods;

                //授课时间
                var sm_shijian = new Array();
                var chenked=$(".showke_time:checked").each(function(){
                   sm_shijian.push($(this).val()); 
                })
                data.field.sm_shijian = sm_shijian;

                //console.log(data);
                // data.field.content = layedit.getContent(editIndex);

                //发异步，把数据提交给php
                $.ajax({
                    url: "{:U('admin/laoshi/showke_info_add')}",//请求地址
                    type: "post",//请求方式
                    dataType: "json",//返回数据类型
                    data: data.field,//发送的参数
                    })
                    .done(function(response) {
                          if(response.error==0){
                             layer.msg(response.info ,{icon:5});
                          }else{
                            layer.alert(response.info, {icon: 6},function () {
                                // 获得frame索引
                                var index = parent.layer.getFrameIndex(window.name);
                                //关闭当前frame
                                parent.layer.close(index);
                            });
                          }
                      })
                    .fail(function() {
                        alert("ajxs交互失败");
                    })  
                return false;
              });
              
              
            });
        </script>
    </body>

</html>